package com.jiuyou.clientController.subscribe;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.subscribe.domain.Subscribe;
import com.ruoyi.subscribe.service.ISubscribeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消息订阅Controller
 *
 * @author ruoyi
 * @date 2025-05-14
 */
@RestController
@RequestMapping("/client/subscribe")
public class SubscribeController extends BaseController
{
    @Autowired
    private ISubscribeService subscribeService;

    /**
     * 查询消息订阅列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Subscribe subscribe)
    {
        startPage();
        List<Subscribe> list = subscribeService.selectSubscribeList(subscribe);
        return getDataTable(list);
    }

    /**
     * 导出消息订阅列表
     */
    @Log(title = "消息订阅", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Subscribe subscribe)
    {
        List<Subscribe> list = subscribeService.selectSubscribeList(subscribe);
        ExcelUtil<Subscribe> util = new ExcelUtil<Subscribe>(Subscribe.class);
        return util.exportExcel(list, "消息订阅数据");
    }

    /**
     * 获取消息订阅详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(subscribeService.selectSubscribeById(id));
    }

    /**
     * 新增消息订阅
     */
    @Log(title = "消息订阅", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Subscribe subscribe)
    {
        return toAjax(subscribeService.insertSubscribe(subscribe));
    }

    /**
     * 修改消息订阅
     */
    @Log(title = "消息订阅", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Subscribe subscribe)
    {
        subscribe.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(subscribeService.updateSubscribe(subscribe));
    }

    /**
     * 删除消息订阅
     */
    @Log(title = "消息订阅", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(subscribeService.logicDeleteSubscribe(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
